<template>
  <div class="topBar">
    <div class="wrap">
      <div class="l">
        <span @click="gologin"
          >欢迎<span class="userName">{{ shopcarList.userName }}</span
          >来到丛台工业品集采平台！</span
        >
        <span v-if="!user" @click="gologin">请登录</span>
        <span v-if="!user" @click="goRegister">免费注册</span>
      </div>
      <div class="r">
        <ul>
          <li @click="goHome">商城首页</li>
          <li @click="goProfile">个人中心</li>
          <li @click="goMerchant" v-if="shopcarList.type == 1">商家入驻</li>
          <li @click="goMyShop" v-else-if="shopcarList.type == 2">我的店铺</li>
          <li @click="goTerminal" v-else-if="shopcarList.type == 3">运营端</li>
          <li>
            <img src="/images/icon@2x.png" width="16px" height="16px" alt="" />
            帮助中心
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { getShoppingcarInfo } from "@/api/mallApi/congLinMall";
import store from "@/store";
export default {
  name: "HeGangProjectTopBar",

  data() {
    return {
      shopcarList: {},
    };
  },
  created() {
    console.log("store顶部", store.state.user);
    if (store.state.user.userId) {
      this.getShoppingcarInfo();
    }
  },
  computed: {
    user() {
      return store.state.user.userId;
    },
  },
  mounted() {},

  methods: {
    goRegister() {
      this.$router.push({
        path: "/mall/register",
      });
    },
    getShoppingcarInfo() {
      //购物车展示信息
      getShoppingcarInfo().then((res) => {
        console.log("topbar", res);
        this.shopcarList = res.data;
      });
    },
    gologin() {
      window.location.href = "/login?redirect=mall%2Fcontainer";
    },
    goHome() {
      this.$router.push({
        path: "/mall/container",
      });
    },
    goProfile() {
      this.$router.push({
        path: "/mall/profile/information",
      });
    },
    goCollect() {
      this.$router.push({
        path: "/mall/profile/myFavorite",
      });
    },
    goMerchant() {
      this.$router.push({
        path: "/mall/settled",
      });
    },
    goMyShop() {
      this.$router.push({
        path: "/home",
      });
    },
    goTerminal() {
      this.$router.push({
        path: "/home",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.topBar {
  height: 44px;
  background: #f3f3f4;
  line-height: 44px;
  // background-image: url("/images/1.png"); /* 这里替换成你想要作为背景的图片路径 */
  // background-size: auto; /* 保持比例不变地调整背景图像来完全覆盖容器 */

  display: flex;
  .wrap {
    background-color: #f3f3f4;
    height: 44px;
    display: flex;
    justify-content: space-between;
    .l {
      display: flex;
      cursor: pointer;
      .userName {
        color: red;
        font-weight: bold;
      }
      span:nth-child(2) {
        margin-left: 24px;
      }
      span:nth-child(3) {
        margin-left: 20px;
      }
      span {
        font-family: "Source Han Sans CN";
        font-weight: 400;
        font-size: 14px;
        text-align: left;
        color: #626262;
        &:nth-child(2) {
          color: #1289ff;
        }
      }
    }
    .r ul {
      display: flex;

      li {
        display: flex;
        align-items: center;
        font-family: "Source Han Sans CN";
        font-weight: 400;
        font-size: 14px;
        text-align: left;
        color: #626262;
        cursor: pointer;

        &:last-child {
          &::after {
            width: 0 !important;
            margin: 0 !important;
          }
        }

        /* 设置相对定位 */
        &::after {
          margin: 0 50px;
          width: 2px;
          height: 1.5em;
          content: "";
          background-color: #b4b2b2;
        }
      }
    }
  }
}
</style>
